﻿using System;
using System.Collections.Generic;
using ControleRepresentante.Logic.Models;
using ControleRepresentante.Migration.Models;
using ControleRepresentante.Migration.Repositories;

namespace ControleRepresentante.Migration.Steps
{
    internal class TransportadoraMigrationStep : MigrationStepBase
    {
        public override void Migrate(Guid representanteId, MigrationStatus migrationStatus, ControleRepresentanteRepository controleRepresentanteRepository, ZTRepository ztRepository, Guid userId)
        {
            migrationStatus.CurrentStep = "Migrate Transportadoras";

            int total = ztRepository.GetTotalTransportadoras();

            IEnumerable<ZTTransportadora> ztTransportadoras = ztRepository.GetTransportadoras();

            int index = 0;
            foreach (ZTTransportadora ztTransportadora in ztTransportadoras)
            {
                Guid transportadoraId = GetTransportadoraId(ztTransportadora.Id);
                controleRepresentanteRepository.CreateTransportadora(representanteId, transportadoraId, ztTransportadora.RazaoSocial);
                controleRepresentanteRepository.CreateContato(transportadoraId, ContatoType.TelefoneComercial, true, ztTransportadora.Telefone);
                migrationStatus.SetCurrentProgress(++index, total);
            }
        }
    }
}